<!--
 * @Author: wangming
 * @Date: 2022-08-03 11:26:42
 * @LastEditors: wangming
 * @LastEditTime: 2022-08-03 16:09:19
 * @FilePath: /hanma-paas-fed/Users/wm/瀚川/hanma-application-designer-fed/src/pageComponents/components/__form/hlModelSelect/index.vue
 * @Description: 
-->
<template>
  <el-input
    v-if="isEdit"
    :style="{
      width: config.__config.width + '%',
    }"
    :placeholder="config.__config.placeholder"
  />
  <div v-else-if="config.__config.viewInfo">
    {{ showlabel }}
  </div>
  <el-select
    @change="changes"
    v-else
    clearable
    :disabled="disabled"
    filterable
    :value="value"
    @input="(v) => $emit('input', v)"
    :placeholder="config.__config.placeholder"
    :style="{
      width: config.__config.width + '%',
    }"
  >
    <el-option
      v-for="item in listData"
      :key="item.id"
      :value="item.code"
      :label="`${item.name}【${item.code}】`"
      v-show="item.code !== 'deleted'"
    />
  </el-select>
</template>

<script>
import myMixin from "@/pageComponents/myMixin";
import vmMixin from "@/pageComponents/vmMixin";
import { getHmentitymodelList } from "@/apis/paas/HmEntityModelController.js";
export default {
  mixins: [myMixin, vmMixin],
  vmEvents: {
    getSelectData() {
      if (this.value) {
        return this.listData.find((i) => i.code == this.value);
      }
    },
  },
  data() {
    return {
      listData: [],
    };
  },
  async created() {
    if (!this.config.__config.modelCode) return;
    this.listData = await getHmentitymodelList(
      {
        modelKey: this.config.__config.modelCode,
        activated: true,
      },
      { useCache: true }
    );
  },
  computed: {
    showlabel() {
      if (this.value) {
        return this.listData.find((i) => i.code == this.value)?.name;
      }
    },
  },
  methods: {
    changes(v) {
      this.runEventName("change", { values: v });
    },
  },
};
</script>

<style scoped lang="scss">
</style>
